<?php
namespace app\index\controller;

class Culture extends BaseHome
{
//$lbp=db("lb")->where("fid=12")->find();
//$this->assign("lbp",$lbp);
//
//$lbm=db("lb")->where("fid=13")->find();
//$this->assign("lbm",$lbm);
//
//$re=db("about")->where("id=4")->find();
//$this->assign("re",$re);
    public function index()
    {
        $lbp=db("lb")->where("fid=12")->find();
        $this->assign("lbp",$lbp);

        $lbm=db("lb")->where("fid=13")->find();
        $this->assign("lbm",$lbm);

        $id=\input('id');
        if(empty($id)){
            $re=db("xm_type")->order("ty_id asc")->limit(1)->find();
            $id=$re['ty_id'];
        }
        $tui=db("xm")->where("status=1 and groom=1 and fid=$id")->order('sort asc')->find();
        $this->assign("tui",$tui);

        $res=db("xm_type")->where("fid=0")->order("ty_id asc")->select();
        foreach ($res as $key => &$val){
            $val['child'] = db("xm_type")->where("fid=".$val['ty_id'])->order("ty_id asc")->select();
        }
        $this->assign("res",$res);

        $list=db("xm")->where("fid=$id and status=1")->order(['sort'=>'asc','groom'=>'asc'])->paginate(4);
        $this->assign("list",$list);

        $page=$list->render();
        $this->assign("page",$page);

        $type=db("xm_type")->where("ty_id=$id")->find();
        $this->assign("type",$type);



        return \view('index');
    }
    public function salon()
    {
        $lbp=db("lb")->where("fid=12")->find();
        $this->assign("lbp",$lbp);
        
        $lbm=db("lb")->where("fid=13")->find();
        $this->assign("lbm",$lbm);
        
        $res=db("salon")->where("status=1")->order("sort asc")->paginate(6);
        $this->assign("res",$res);
        
        $page=$res->render();
        $this->assign("page",$page);
        
        return \view('salon');
    }
    public function detail()
    {
        $lbp=db("lb")->where("fid=12")->find();
        $this->assign("lbp",$lbp);

        $lbm=db("lb")->where("fid=13")->find();
        $this->assign("lbm",$lbm);

        $id=\input('id');
        $re=db("xm")->where("id=$id")->find();
        $this->assign("re",$re);

        db("xm")->where("id=$id")->setInc("browse",1);

        //上一篇
        $pre=db('xm')->where("id<$id and status=1")->order("id desc")->limit("1")->find();
        $this->assign("pre",$pre);

        //下一篇
        $nre=db('xm')->where("id>$id and status=1")->order("id asc")->limit("1")->find();
        $this->assign("nre",$nre);

        $res=db("xm_type")->where("fid=0")->order("ty_id asc")->select();
        foreach ($res as $key => &$val){
            $val['child'] = db("xm_type")->where("fid=".$val['ty_id'])->order("ty_id asc")->select();
        }
        $this->assign("res",$res);
        $type=db("xm_type")->where("ty_id=$id")->find();
        if(!empty($type['fid'])){
            $type = db("xm_type")->where("fid=".$type['fid'])->find();
        }
        $this->assign("type",$type);

        return \view('detail');
    }
    
    
    
    
    
}